$(function() {

    $("body").css("opacity","1")

    $("#xuefenxiuqu").click(function () {
        $(this).css({"background-color": "#007dd2", "color": "white"})
        $("#jihuakecheng").css({"background-color": "white", "color": "black"})
        $("#quanxiaotongxuan").css({"background-color": "white", "color": "black"})
        $("#sjkc").show(500)
        $("#ckcj").hide(500)
        $("#xgcj").hide(500)
    });

    $("#jihuakecheng").click(function () {
        $(this).css({"background-color": "#007dd2", "color": "white"})
        $("#xuefenxiuqu").css({"background-color": "white", "color": "black"})
        $("#quanxiaotongxuan").css({"background-color": "white", "color": "black"})
        $("#sjkc").hide(500)
        $("#ckcj").show(500)
        $("#xgcj").hide(500)
    });

    $("#quanxiaotongxuan").click(function () {
        $(this).css({"background-color": "#007dd2", "color": "white"})
        $("#xuefenxiuqu").css({"background-color": "white", "color": "black"})
        $("#jihuakecheng").css({"background-color": "white", "color": "black"})
        $("#sjkc").hide(500)
        $("#ckcj").hide(500)
        $("#xgcj").show(500)
    });


    var username = localStorage.getItem("username");

    $.post("/xjxt/suojiaokecheng?username=" + username + "", function (res) {

        var hehe = JSON.parse(res);
        console.log(hehe);
        $("#suojiaokecheng").append("<tr id='first'>" + "<td>" + "课程" + "</td>" + "<td>" + "课程号" + "</td>" + "<td>" + "课程性质" + "</td>" + "<td>" + "时间" + "</td>" + "</tr>");
        $.each(hehe, function (colIndex, col) {

            var th;
            th += "<td>" + col.kecheng + "</td>" + "<td>" + "<a href='#' id='" + col.kechenghao + "'>" + col.kechenghao + "</a>" + "</td>" + "<td>" + col.kechengxingzhi + " </td>" + "<td>" + col.shijian + " </td>";
            $("#suojiaokecheng").append("<tr>" + th + "</tr>");


            $("#" + col.kechenghao + "").click(function () {

                $.post("/xjxt/chaxunquanbu?kechenghao=" + col.kechenghao + "", function (res) {
                    var hehe = JSON.parse(res);
                    console.log(hehe);
                    $("#xueshengchengji tr").remove();
                    $("#xueshengchengji").append("<tr id='first1'>" + "<td>" + "学号" + "</td>" + "<td>" + "姓名" + "</td>" + "<td>" + "课程" + "</td>" + "<td>" + "课程号" + "</td>" + "<td>" + "正考" + "</td>" + "<td>" + "补考" + "</td>" + "</tr>");
                    $.each(hehe, function (colIndex, col) {
                        var th;
                        th += "<td>" + col.username + "</td>" + "<td>" + col.name + "</td>" + "<td>" + col.kecheng + " </td>" + "<td>" + col.kechenghao + " </td>" + "<td>" + "<input type='text' value='" + col.zhengkao + "' id='zhengkao"+col.username+"'>" + " </td>" + "<td>" + "<input type='text' value='" + col.bukao + "' id='bukao"+col.username+"'>" + " </td>" ;
                        $("#xueshengchengji").append("<tr>" + th + "</tr>");


                        $("#cjtijiao").click(function () {
                        	
                            $.post("/xjxt/chengjixiugai", {
                                "username": col.username,
                                "kechenghao": col.kechenghao,
                                "zhengkao": $("#zhengkao"+col.username).val(),
                                "xuefen": col.xuefen,
                                "cjzhuangtai": col.cjzhuangtai
                            }, function (res) {
                                if (res == "2") {
                                    alert(""+ col.name +"提交失败");
                                    window.location.reload()
                                }
                                if (res == "1") {
                                    alert(""+ col.name +"提交成功");
                                    window.location.reload()
                                }
                                if (res == "3") {
                                    alert(""+ col.name +"成绩已经提交过无法再次提交");
                                    window.location.reload()
                                }

                            });

                        });

                        $("#cjbaocun").click(function () {

                            $.post("/xjxt/chengjibaocun", {
                                "username": col.username,
                                "kechenghao": col.kechenghao,
                                "zhengkao": $("#zhengkao"+col.username).val(),
                                "xuefen": col.xuefen,
                                "cjzhuangtai": col.cjzhuangtai
                            }, function (res) {
                                if (res == "2") {
                                    alert(""+ col.name +"保存失败");
                                    window.location.reload()
                                }
                                if (res == "1") {
                                    alert(""+ col.name +"保存成功");
                                    window.location.reload()
                                }
                                if (res == "3") {
                                    alert(""+ col.name +"成绩已经提交无法保存");
                                    window.location.reload()
                                }

                            });

                        });

                        $("#bktijiao").click(function () {
                            if($("#zhengkao"+col.username).val() >= 60 )
                            {
                                alert(""+ col.name +"不需要填写补考成绩");
                            }

                            $.post("/xjxt/bukaotijiao", {
                                "username": col.username,
                                "kechenghao": col.kechenghao,
                                "bukao": $("#bukao"+col.username).val(),
                                "xuefen": col.xuefen,
                                "cjzhuangtai": col.cjzhuangtai
                            }, function (res) {
                                if (res == "2") {
                                    alert(""+ col.name +"提交失败");
                                    window.location.reload()
                                }
                                if (res == "1") {
                                    alert(""+ col.name +"提交成功");
                                    window.location.reload()
                                }
                                if (res == "3") {
                                    alert(""+ col.name +"补考成绩已经提交过无法再次提交");
                                    window.location.reload()
                                }

                            });

                        });
                      

                    });




                });

                $("#jihuakecheng").css({"background-color": "#007dd2", "color": "white"})
                $("#xuefenxiuqu").css({"background-color": "white", "color": "black"})
                $("#quanxiaotongxuan").css({"background-color": "white", "color": "black"})
                $("#sjkc").hide(500)
                $("#ckcj").show(500)
                $("#xgcj").hide(500)
            });

        });
    });

    $("input[type=text]").change(function () {
        var searchText = $(this).val();//获取输入的搜索内容
        if (searchText != "") {

            $("#suojiaokecheng tr:not('#first')").hide().filter(":contains('"+searchText+"')").show();
        }
        else {
            $("#suojiaokecheng tr").show();
        }
    })
    $("input[type=submit]").click(function () {
        $("searchText").change();
    })



    $("input[type=text]").change(function () {
        var searchText = $(this).val();//获取输入的搜索内容
        if (searchText != "") {

            $("#xueshengchengji tr:not('#first1')").hide().filter(":contains('"+searchText+"')").show();
        }
        else {
            $("#xueshengchengji tr").show();
        }
    })
    $("input[type=submit]").click(function () {
        $("searchText").change();
    })

});







